<?php

namespace app\admin\controller;

use app\BaseController;

class Upload extends BaseController
{

    public function ajaxUpload(){

        // 获取表单上传文件
        $files = request()->file('thumbs');

        try {
//            validate(['img'=>'fileSize:10240|fileExt:jpg,png,jpeg,webp'])
//                ->check($files);

                $savename = \think\facade\Filesystem::putFile( 'topic', $files);


            return $this->success(['path'=>'/storage/'.$savename]);

        } catch (\think\exception\ValidateException $e) {

            return $this->error($e->getMessage());
        }

    }

    public function ajaxUploadFile(){

        // 获取表单上传文件
        $files = request()->file('file');

        try {
//            validate(['img'=>'fileSize:10240|fileExt:jpg,png,jpeg,webp'])
//                ->check($files);

            $savename = \think\facade\Filesystem::putFile( 'topic', $files);


            return $this->success(['path'=>'/storage/'.$savename]);

        } catch (\think\exception\ValidateException $e) {

            return $this->error($e->getMessage());
        }

    }


    public function editUploadFile(){

        // 获取表单上传文件
        $files = request()->file('file');

        try {
//            validate(['img'=>'fileSize:10240|fileExt:jpg,png,jpeg,webp'])
//                ->check($files);

            $savename = \think\facade\Filesystem::putFile( 'topic', $files);


            return json(['code'=>0,'msg'=>'success','data'=>['src'=>'/storage/'.$savename,'title'=>$files->getFilename()]]);
//            return $this->success(['path'=>'/storage/'.$savename]);

        } catch (\think\exception\ValidateException $e) {

            return $this->error($e->getMessage());
        }

    }

}